package com.burst.reptile.modular.monitor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.burst.reptile.common.utils.poi.ExcelUtil;
import com.burst.reptile.framework.aspectj.lang.annotation.Log;
import com.burst.reptile.framework.aspectj.lang.enums.BusinessType;
import com.burst.reptile.framework.web.controller.BaseController;
import com.burst.reptile.framework.web.result.LayuiResult;
import com.burst.reptile.framework.web.result.Result;
import com.burst.reptile.modular.monitor.entity.SysOperLog;
import com.burst.reptile.modular.monitor.service.ISysOperLogService;

import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author wujin
 * @since 2020-05-22
 */
@RestController
@RequestMapping("/monitor/operlog")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysOperLogController extends BaseController {

	private final ISysOperLogService operLogService;

	/**
	 * 操作日志列表
	 * @param operLog
	 * @return
	 */
	@PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
	@GetMapping("/list")
	public LayuiResult<Object> list(SysOperLog operLog) {
		Page<SysOperLog> page = startPage();
		Page<SysOperLog> list = operLogService.selectPageOperLogList(page, operLog);
		return LayuiResult.success(list.getTotal(), list.getRecords());
	}

	/**
	 * 导出操作日志
	 * @param operLog
	 * @return
	 */
	@Log(title = "操作日志", businessType = BusinessType.EXPORT)
	@PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
	@GetMapping("/export")
	public Result<Object> export(SysOperLog operLog) {
		List<SysOperLog> list = operLogService.selectOperLogList(operLog);
		ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
		return util.exportExcel(list, "操作日志");
	}

	/**
	 * 删除操作日志
	 * @param operIds
	 * @return
	 */
	@PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
	@DeleteMapping("/remove/{operIds}")
	public Result<Object> remove(@PathVariable Long[] operIds) {
		return Result.success(operLogService.deleteOperLogByIds(operIds));
	}

	/**
	 * 清空操作日志
	 * @return
	 */
	@Log(title = "操作日志", businessType = BusinessType.CLEAN)
	@PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
	@DeleteMapping("/clean")
	public Result<Object> clean() {
		operLogService.cleanOperLog();
		return Result.success("success");
	}

}
